package com.luohh.treeroom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luohh.treeroom.dto.BasePageResult;
import com.luohh.treeroom.dto.BaseResult;
import com.luohh.treeroom.entity.ProductCategory;
import com.luohh.treeroom.mapper.ProductCategoryMapper;
import com.luohh.treeroom.service.IProductCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 罗辉煌
 * @since 2020-02-15
 */
@Service
public class ProductCategoryServiceImpl extends ServiceImpl<ProductCategoryMapper, ProductCategory> implements IProductCategoryService {

    @Autowired
    IProductCategoryService productCategoryService;

    @Override
    public BaseResult getList(){
        QueryWrapper<ProductCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_valid",1);
        queryWrapper.eq("pid",-1 );
        BaseResult  productCategory = new BaseResult(list(queryWrapper));
        return   productCategory;
    }

    @Override
    public BaseResult getDetailList(Integer id){
        List<ProductCategory> bootTree = bootTree(id);
        return new BaseResult(bootTree);
    }
    private List<ProductCategory> bootTree(Integer id){
        QueryWrapper Trees = new QueryWrapper<>().eq("pid",id);
        List<ProductCategory> TreesRealt = list(Trees);
        for ( ProductCategory tree : TreesRealt){
            Integer id2 = tree.getId();
            List<ProductCategory> bootTree = bootTree(id2);
        }
        return TreesRealt;
    }
}
